package com.chenwut.threadDemo.exercise_2;

/**
 * @author ChenPi
 * @since 2024/09/19 16:46
 */
public class MyThread extends Thread {

    static int ticket = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread.class) {
                if (100 - ticket == 10) {
                    break;
                }
                try {
                    Thread.sleep(10);
                    ticket++;
                    System.out.println(getName() + " 发放了 礼品：" + ticket + " 剩余礼品数为： " + (100 - ticket));
                } catch (InterruptedException e) {

                }
            }
        }
    }
}
